import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../../../lib_runtime/logger.dart';
import '../../../../lib_user/user_manager.dart';
import 'doufeng_tacit_model.dart';
import 'doufeng_tacit_dialog_manager.dart';

import 'package:flutter/services.dart';
import 'package:get/get.dart';

import 'tacit_count_down_painter.dart';

class QuestionAnswerWidget extends StatefulWidget {
  // static String tag = "QuestionAnswerWidget";

  @override
  State<QuestionAnswerWidget> createState() => _QuestionAnswerWidgetState();
}

class _QuestionAnswerWidgetState extends State<QuestionAnswerWidget>
    with TickerProviderStateMixin {
  @override
  Widget build(BuildContext context) {
    return Consumer<DoufengTacitModel>(builder: (context, model, child) {
      List<Widget> answers = [];
      // for (int i = 0; i < (model.tacitPush?.quest.answers.length ?? 0); i++) {
      //   TacitAnswer answer = model.tacitPush!.quest.answers[i];
      //   if (answer.title == model.selectedAnswer?.title) {
      //     answers.add(CupertinoButton(
      //       minSize: 0,
      //       padding: EdgeInsets.zero,
      //       onPressed: () {
      //         model.tacitAnswer(model.tacitPush?.quest.index ?? 0, i);
      //       },
      //       child: Container(
      //         width: 112,
      //         height: 36,
      //         decoration: BoxDecoration(
      //           gradient: const LinearGradient(
      //             colors: [Color(0xFFEC6FA9), Color((0xFFEA3B7B))],
      //           ),
      //           borderRadius: BorderRadius.circular(18),
      //         ),
      //         alignment: Alignment.center,
      //         child: Text(
      //           answer.title,
      //           style: const TextStyle(
      //             color: Colors.white,
      //             fontSize: 14,
      //             fontWeight: FontWeight.w500,
      //           ),
      //         ),
      //       ),
      //     ));
      //   } else {
      //     answers.add(CupertinoButton(
      //       minSize: 0,
      //       padding: EdgeInsets.zero,
      //       onPressed: () {
      //         model.tacitAnswer(model.tacitPush?.quest.index ?? 0, i);
      //       },
      //       child: Container(
      //         width: 112,
      //         height: 36,
      //         decoration: BoxDecoration(
      //           border: Border.all(color: const Color(0xFF4B3593), width: 1),
      //           borderRadius: BorderRadius.circular(18),
      //         ),
      //         alignment: Alignment.center,
      //         child: Text(
      //           answer.title,
      //           style: const TextStyle(
      //             color: Color(0xFF8F5CFF),
      //             fontSize: 14,
      //             fontWeight: FontWeight.w500,
      //           ),
      //         ),
      //       ),
      //     ));
      //   }
      // }

      return Container(
        padding: const EdgeInsets.symmetric(
          horizontal: 34,
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            SizedBox(
              height: 30,
              child: Stack(
                children: [
                  Align(
                    alignment: Alignment.centerLeft,
                    child: SizedBox(
                      width: 30,
                      height: 30,
                      child: CustomPaint(
                          painter: TacitCountDownPainter(
                        width: 30,
                        borderWidth: 4.2,
                        countDownSum: 5,
                        fontSize: 14,
                        factor: model.getAnimationController(this),
                      )),
                    ),
                  ),
                  const Align(
                    alignment: Alignment.center,
                    child: Text(
                      "快问快答",
                      style: TextStyle(
                        fontSize: 16,
                        fontWeight: FontWeight.w500,
                        color: Colors.white,
                      ),
                    ),
                  ),
                  Align(
                    alignment: Alignment.centerRight,
                    child: CupertinoButton(
                      onPressed: () {
                        /// 结束默契测试
                        // DoufengTacitDialogManager.showStopTacitDialog();

                        DoufengTacitDialogManager.showStopTacitDialog(
                          Get.context!,
                          UserManager.instance.currentUser!,
                          () {},
                          () {},
                        );
                      },
                      minSize: 0,
                      padding: EdgeInsets.zero,
                      child: Row(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          Image.asset(
                            "assets/images/ic_doufeng_tacit_end.png",
                            width: 12,
                            height: 12,
                            fit: BoxFit.contain,
                          ),
                          const SizedBox(
                            width: 5,
                          ),
                          const Text(
                            "结束",
                            style: TextStyle(
                              fontSize: 12,
                              fontWeight: FontWeight.w400,
                              color: Colors.white,
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
            const SizedBox(height: 18),
            const Text(
              "请您在规定时间内迅速做答",
              style: TextStyle(
                fontSize: 12,
                fontWeight: FontWeight.w400,
                color: Colors.white,
              ),
              textAlign: TextAlign.center,
            ),
            const Text(
              "model.tacitPush?.quest.title",
              style: TextStyle(
                fontSize: 18,
                fontWeight: FontWeight.w500,
                color: Colors.white,
              ),
              textAlign: TextAlign.center,
            ),
            const SizedBox(
              height: 30,
            ),
            Wrap(
              children: answers,
            ),
            const SizedBox(
              height: 14,
            ),
            const Text(
              'model.tacitPush!.quest.index',
              style: TextStyle(
                fontSize: 13,
                fontWeight: FontWeight.w500,
                color: Colors.white,
              ),
              textAlign: TextAlign.center,
            ),
          ],
        ),
      );
    });
  }

  String problemIndicator(int index) {
    String tmpStr;

    tmpStr = (index + 1).toString();

    RLog.d("tacit_understanding  $tmpStr   index:$index");

    return "$tmpStr/10";
  }
}
